<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * change position of data record up and down
 * used from category.page.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
db::getInstance()->where("category_top", $refValidate->cleanslash($_GET['top']));
$result = db::getInstance()->get("category");

if ($result !== NULL)
{
	foreach ($result as $data)
	{
		if ($data['category_order'] == $refValidate->cleanslash($_GET['order']))
		{
			$idx = $data['category_id'];
			$orderx = $data['category_order'];
			break;
		}
	}

	$data = Array('category_order' => ($orderx - 1));
	db::getInstance()->where("category_id", $idx);
	db::getInstance()->update('category', $data);

	foreach ($result as $data)
	{
		if ($data['category_order'] == $refValidate->cleanslash($_GET['order'] - 1))
		{
			$idx = $data['category_id'];
			$orderx = $data['category_order'];
			break;
		}
	}

	$data = Array('category_order' => ($orderx + 1));
	db::getInstance()->where("category_id", $idx);
	db::getInstance()->update('category', $data);
}
else
{
	message::setErrorRow(_('Databaseerror - Contact the Admin!'), true);
}
?>